//初始化echarts实例
var ec_center = echarts.init(document.getElementById("c2"),"dark");
var mydata = [
	{
	"name": "中国香港",
	"value": 10868
	},
	{
	"name": "广东省",
	"value": 2187
	},
	{
	"name": "四川省",
	"value": 887
	},
	{
	"name": "上海市",
	"value": 1783
	},
	{
	"name": "湖南省",
	"value": 1036
	},
	{
	"name": "北京市",
	"value": 1047
	},
	{
	"name": "天津市",
	"value": 352
	},
	{
	"name": "湖北省",
	"value": 68151
	},
	{
	"name": "河南省",
	"value": 1304
	},
	{
	"name": "浙江省",
	"value": 1320
	},
	{
	"name": "安徽省",
	"value": 994
	},
	{
	"name": "江西省",
	"value": 935
	},
	{
	"name": "江苏省",
	"value": 703
	},
	{
	"name": "重庆市",
	"value": 591
	},
	{
	"name": "山东省",
	"value": 867
	},
	{
	"name": "黑龙江省",
	"value": 1610
	},
	{
	"name": "河北省",
	"value": 1317
	},
	{
	"name": "福建省",
	"value": 548
	},
	{
	"name": "广西壮族自治区",
	"value": 267
	},
	{
	"name": "陕西省",
	"value": 547
	},
	{
	"name": "云南省",
	"value": 231
	},
	{
	"name": "海南省",
	"value": 171
	},
	{
	"name": "贵州省",
	"value": 147
	},
	{
	"name": "山西省",
	"value": 239
	},
	{
	"name": "辽宁省",
	"value": 406
	},
	{
	"name": "甘肃省",
	"value": 187
	},
	{
	"name": "吉林省",
	"value": 573
	},
	{
	"name": "新疆维吾尔自治区",
	"value": 980
	},
	{
	"name": "内蒙古自治区",
	"value": 367
	},
	{
	"name": "宁夏回族自治区",
	"value": 75
	},
	{
	"name": "中国台湾",
	"value": 942
	},
	{
	"name": "青海省",
	"value": 18
	},
	{
	"name": "中国澳门",
	"value": 48
	},
	{
	"name": "西藏自治区",
	"value": 1
	}
	];

    $('body').on('click','.btn',function(){
        var target = $(this).attr('id');
        if(target == 'total'){
            get_center_data();
            $('#now').css('background','#3398DB');
            $('#now').css('color','#fff');
            $('#total').css('background','#fff');
            $('#total').css('color','#3398DB');
        }else{
            $('#total').css('background','#3398DB');
            $('#total').css('color','#fff');
            $('#now').css('background','#fff');
            $('#now').css('color','#3398DB');
            get_center_data_now();
        }
    })
    $('body').on('click','.ceng',function(){
        $('#myModal').css('display','none');
        $('.ceng').css('display','none');

    })
var optionMap = {
	  	backgroundColor: '#00008B',
		title: {
			text: '',
			subtext: '',
			x: 'left'
		},
		tooltip: {
			trigger: 'item'
		},
		//左侧小导航图标
		visualMap: {
			show: true,
			x: 'left',
			y: 'bottom',
			textStyle: {
				fontSize: 8
			},
			splitList: [{
					start: 1,
					end: 9
				},
				{
					start: 10,
					end: 99
				},
				{
					start: 100,
					end: 999
				},
				{
					start: 1000,
					end: 9999
				},
				{
					start: 10000
				}
			],
			color: ['#8A3310','#C64918', '#E55B25','#F2AD92', '#F9DCD1']
		},
        //工具框，可以选择
      	toolbox: {
			x:650,
        	y:30,
			show:true,
      		feature: {
      			saveAsImage: {}, //下载工具
                dataView: {} 
      		},

      	},
			//配置属性
			series: [{
				name: '累积确诊人数',
				type: 'map',
				mapType: 'china',
				roam: false,
				itemStyle: {
					normal: {
						borderWidth: .5,
						borderColor: '#009fe8',
						areaColor: '#ffefd5'
					},
					emphasis: {
						borderWidth: .5,
						borderColor: '#4b0082',
						areaColor: '#fff'
					}
				},
				label: {
					normal: {
						show: true, //省份名称
						fontSize: 8
					},
					emphasis: {
						show: true,
						fontSize: 8
					}
				},
				data: [{
					"name": "广东",
					"value": 2187
					}] //数据
			}]
		};

		//使用制定的配置项和数据显示图表
		ec_center.setOption(optionMap);
        ec_center.on('click',function(params){
            var area = params.data.name;
            $('#myModal').css('display','block');
            $('.ceng').css('display','block');
            $.ajax({
                url:"/get_news_data/"+area,
                success: function(data) {
                    console.log(data);
                    var _html = '';
                    for(j in data){
                        let time = new Date((data[j].eventTime)*1000);
                        let month = time.getMonth() + 1;
                        let day  = time.getDate();
                        let hours = time.getHours();
                        let minute  = time.getMinutes();
                        if(month < 10){
                            month = '0'+month;
                        }
                        if(day < 10){
                            day = '0'+day;
                        }
                        if(hours < 10){
                            hours = '0'+hours;
                        }
                        if(minute < 10){
                            minute = '0'+minute;
                        }
                        let date = month+'月'+day+'日'+' '+hours+':'+minute;
                        if(j<=10){
                            _html += '<div class="list-item">'+
                                '<a target="_blank" href="'+data[j].eventUrl+'">'+
                                '<span class="Virus_1-1-303_2LSxMS" style="top:'+(2+(j*6))+'rem"></span>'+
                                '<span class="datatime" style="top:'+(1.5+(j*6))+'rem">'+date+'</span>'+
                                '<div class="nr" style="top:'+(4+(j*6))+'rem">'+
                                    data[j].eventDescription+
                                '</div>'+
                            '</div>';
                        }else{
                            break;
                        }
                    }
                    $('.main').html(_html)
                    $('.title').html(area+'疫情新闻')
                },
                error: function(xhr, type, errorThrown) {
        
                }
            })
        })
